<?php
session_start();
include_once "checkAdmin.php";
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>后台管理</title>
    <style>
        h1 {
            text-align: center;
        }

        .main {
            width: 50%;
            margin: 0 auto
        }

        .main table {
            width: 100%
        }
        a{color: cornflowerblue;text-decoration: none}
        a:hover{color: crimson;text-decoration: underline}
    </style>
</head>
<body>

<h1>车辆管理</h1>

<?php
include_once "nav.php";
include_once "conn.php";
include_once "page.php";
$sql = "select count(1) total from car  ";
$result = mysqli_query($conn, $sql);
//新增内容
$info = mysqli_fetch_array($result);
$count_rows = $info['total'];
$perPage = 6;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
//引用分页函数
pageft($count_rows, $count_rows,$perPage);
$sql = "select * from car order  by carnum desc limit $firstCount, $displayPG";
$result = mysqli_query($conn, $sql);
?>
<table border="0" width="80%" align="center">
    <tr>
        <td align="center">
            <table align="center" width="100%" border="1" bordercolor="black" cellspacing="0" cellpadding="10"
                   style="border-collapse: collapse" id="admin">
                <tr>
                    <td align="center">序号</td>
                    <td align="center">车辆名称</td>
                    <td align="center">车辆描述</td>
                    <td align="center">车辆图片</td>
                    <td align="center">当前票数</td>
                    <td align="center">操作</td>
                </tr>
                <?php
                $i = ($page - 1) * $perPage + 1;
                while ($info = mysqli_fetch_array($result)) {
                    ?>
                    <tr>
                        <td align="center"><?php echo $i ?></td>
                        <td align="center"><?php echo $info['carname']; ?></td>
                        <td align="center"><?php echo $info['description'] ; ?></td>
                        <td align="center"><img src="<?php echo $info['carpic']; ?>" width="200"></td>
                        <td align="center"><?php echo $info['carnum']; ?></td>
                        <td align="center">
                            <a href="modify.php?id=<?php echo $info['id']; ?>">编辑资料</a>
                            <a href="del.php?id=<?php echo $info['id']; ?>">删除车辆</a>
                        </td>
                    </tr>
                    <?php
                    $i++;
                }
                ?>
            </table>
        </td>
    </tr>
    <tr>
        <td align="right"><?php
            //页尾显示
            echo $pageNav;
            ?></td>
    </tr>
    <tr>
        <td>
            <form action="postAddCar.php" method="post" onSubmit="return Validator.Validate(this,3)" enctype="multipart/form-data">
                <table style="border-collapse:collapse " border="1" width="100%" cellpadding="10" bordercolor="gray" cellspacing="0">
                    <tr>
                        <td align="center">车辆名称</td>
                        <td align="left">
                            <input name="carname" >
                        </td>
                    </tr>
                    <tr>
                        <td align="center">车辆描述</td>
                        <td align="left">
                            <textarea name="description"></textarea>
                        </td>
                    </tr>
                    <tr>
                        <td align="center">车辆图片</td>
                        <td align="left">
                            <input type="file" name="carpic">
                        </td>
                    </tr>
                    <tr>
                        <td align="center"><input type="submit" value="提交"></td>
                        <td align="left">
                            <input type="reset" value="重置">
                        </td>
                    </tr>
                </table>
            </form>
        </td>
    </tr>
</table>
<script src="jquery.js"></script>
</body>
</html>